package com.woniu.adapter;

import com.woniu.outlet.mysql.SellRateDao;
import com.woniu.outlet.mysql.po.SellRateMySQL;
import com.woniu.outlet.mysql.po.SellRateMySQLExample;
import com.woniu.service.domain.SellRate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class SellRateAdapter {

    @Autowired
    private SellRateDao sellRateDao;

    /**
     * 根据产品持有天数查询手续费利率
     * @param day 持有天数
     * @return
     */
    public SellRateMySQL getSellRateByDay(int day){
        SellRateMySQL sellRateMySQL = null;
        SellRateMySQLExample example = new SellRateMySQLExample();
        if(day>730){
            return sellRateDao.selectByPrimaryKey(4L);
        }
        example.createCriteria().andGreaterThanEqualLessThanOrEqualTo((long) day).andLessThanGreaterThan((long) day);
        List<SellRateMySQL> sellRateMySQLS = sellRateDao.selectByExample(example);
        for (SellRateMySQL sellRateSQL : sellRateMySQLS) {
            sellRateMySQL=sellRateSQL;
        }
        return sellRateMySQL;
    }
}
